package org.example.sdpback.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.example.sdpback.domain.entity.Project;
import org.example.sdpback.domain.query.ProjectQuery;
import org.example.sdpback.sdk.response.SdpResponseData;
import org.example.sdpback.service.ProjectService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "项目管理模块")
@RestController
@RequestMapping("/project")
@RequiredArgsConstructor
public class ProjectController {

    private final ProjectService projectService;

    @Operation(summary = "添加项目")
    @PostMapping("/add")
    public SdpResponseData<String> addProject(@RequestBody Project project) {
        projectService.addProject(project);
        return SdpResponseData.success();
    }

    @Operation(summary = "删除项目")
    @PostMapping("/delete")
    @Parameter(name = "projectId", description = "项目id")
    public SdpResponseData<String> deleteProject(Long projectId) {
        projectService.removeById(projectId);
        return SdpResponseData.success();
    }

    @Operation(summary = "修改项目")
    @PostMapping("/update")
    public SdpResponseData<String> updateProject(@RequestBody Project project) {
        projectService.updateProject(project);
        return SdpResponseData.success();
    }

    @GetMapping("/list")
    @Operation(summary = "查询项目")
    @Parameters({
            @Parameter(name = "projectName", description = "项目名称", schema = @Schema(type = "string")),
            @Parameter(name = "username", description = "创建人")
    })
    public SdpResponseData<List<Project>> projectList(@RequestParam(required = false) String projectName, @RequestParam(required = false) String username) {
        List<Project> list = projectService.getProjectList(projectName, username);
        return SdpResponseData.success(list);
    }
}
